package com.lesso.zgs.sunflower.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.lesso.zgs.sunflower.core.ApiResponse;
import com.lesso.zgs.sunflower.pojo.dto.AttendanceRuleDTO;
import com.lesso.zgs.sunflower.pojo.dto.AttendanceRuleQueryDTO;
import com.lesso.zgs.sunflower.pojo.vo.AttendanceRuleVO;
import com.lesso.zgs.sunflower.service.IAttendanceRuleService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 考勤规则 前端控制器
 * </p>
 *
 * @author zgs
 * @since 2025-07-03
 */
@RestController
@RequestMapping("/base/attendance-rule")
public class AttendanceRuleController {
    @DubboReference
    private IAttendanceRuleService attendanceRuleService;

    @PostMapping
    public ResponseEntity<Integer> save(@RequestBody AttendanceRuleDTO dto) {
        return ResponseEntity.ok(attendanceRuleService.save(dto));
    }

    @RequestMapping("/{id}")
    public ResponseEntity<AttendanceRuleDTO> getById(@PathVariable Long id) {
        return ResponseEntity.ok(attendanceRuleService.getById(id));
    }

    @PutMapping
    public ResponseEntity<Integer> update(@RequestBody AttendanceRuleDTO dto) {
        return ResponseEntity.ok(attendanceRuleService.update(dto));
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Integer> delete(@PathVariable Long id) {
        return ResponseEntity.ok(attendanceRuleService.delete(id));
    }

    @GetMapping("/page")
    public ApiResponse<Page<AttendanceRuleVO>> page(AttendanceRuleQueryDTO dto) {
        return ApiResponse.ok("success", attendanceRuleService.page(dto));
    }
} 